<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/base.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户聊天管理</title>
<style type="text/css">
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	.p-c-flexwrapper > span {
		width:80px;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper > .form-control {
		width:180px;
	}
	.datePick {
		display:none;
	}
	.datePick.active {
		display:block;
	}
	.desc-edit-td {
		max-width:200px;
		white-space:pre-wrap!important;
	}
table th,table tr,table td {
	text-align: center;
	vertical-align:middle;
}
</style>
</head>
<body>
	<form style="display:flex;align-items:center;" class="">
		<input type="text" class="layui-input datePick active datePick1" id="test1" style="width:200px;" placeholder="请选择年">
		<input type="text" class="layui-input datePick datePick2" id="test2" style="width:200px;" placeholder="请选择月">
		<input type="text" class="layui-input datePick datePick3" id="test3" style="width:200px;" placeholder="请选择日">
		<select id="chooseDateSelect" style="height:38px;margin:0 16px;">
			<option value="1">按年</option>
			<option value="2">按月</option>
			<option value="3">按天</option>
		</select>
		<button class="layui-btn" type="button" id="button-i-delChat">删除</button>
		<span style="margin-left:30px;">设置群聊发言最低历史充值金额： </span>
		<input class="layui-input input-setup" style="margin-right: 30px;width:150px; " />
		<button class="layui-btn" type="button" id="button-i-setup">修改</button>
	</form>
	<table id="table-i-qqAccountList" class="table table-striped table-bordered table-hover" style="margin-top: 20px;">
		<thead>
			<tr>
			<th style="display:none;"></th>
			<th>用户ID</th>
			<th>聊天内容</th>
			<th>聊天时间</th>
			<th>记录操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script type="text/javascript">
	
	layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  laydate.render({
			    elem: '#test1', //指定元素
		    	type: 'year',
		  });
		  laydate.render({
			    elem: '#test2', //指定元素
		    	type: 'month',
		  });
		  laydate.render({
			    elem: '#test3', //指定元素
		    	type: 'date',
		  });
		});	
	
	function findUserChatMinRechargeMoney(){
		ajax({
			url:"/kajhsgweasdqtwehghasfdnsak6868/findUserChatMinRechargeMoney.do",
			type:"post",
			success:function(data){
				var json=eval('('+data+')')
				$(".input-setup").val(json.data)
			}
		});
	}
	findUserChatMinRechargeMoney();
	$("#button-i-setup").click(function(){
		ajax({
			url:"/kajhsgweasdqtwehghasfdnsak6868/updateUserChatMinRechargeMoney.do",
			type:"post",
			data:{"money":$(".input-setup").val()},
			success:function(data){
				var json=eval('('+data+')')
				if(json.data==1){
					alert("修改成功!");
				}
				findUserChatMinRechargeMoney();
			}
		});
	})
	
	$("#chooseDateSelect").on("change", function(e) {
		var value = $(e.currentTarget).val()
		$(".datePick.active").removeClass("active")
		$(".datePick" + value).addClass("active")
	})
	
	$("#button-i-delChat").on("click", function(e) {
		if ($(".datePick.active").val().trim() === "") {
			return
		}
		ajax({
			url: "/kajhsgweasdqtwehghasfdnsak6868/deleteUserChatRecord.do",
			type: "post",
			data: {
				time: $(".datePick.active").val()
			},
			success: function(data) {
				alert("删除成功!");
				$("#table-i-qqAccountList").DataTable().ajax.reload();
			},
			error: function(status) {
			}
		})				
	})
	
	$("#table-i-qqAccountList").on("click", ".btn-c-delBankInfo", function(e) {
		ajax({
			url: "/kajhsgweasdqtwehghasfdnsak6868/deleteByIdUserChatRecord.do",
			type: "post",
			data: {
				id: Number($(e.currentTarget).closest("tr").find(".id-edit-td").text())
			},
			success: function(data) {
				var newData = JSON.parse(data)
				if (newData.data === 1) {
					alert("删除成功!");
				} 
				$("#table-i-qqAccountList").DataTable().ajax.reload()
			},
			error: function(status) {
			}
		})		
	})
		$("#table-i-qqAccountList").DataTable({
	      // "bPaginate": true,
	      "bLengthChange": true,      
	      "bSort": false,
	      // "bInfo": true,
	      "bAutoWidth": false,
//		         "bServerSide":true,
	      'aLengthMenu':[5,10, 20],
	       "searching": false,
	       "dom": `ftp`,
//		    "searching": true,l
	       "language": {//语言设置  
	            "lengthMenu": "每页显示 _MENU_ 条记录",     
	            "zeroRecords": "没有检索到数据",     
	            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
	            "info": "没有数据",     
	            "oPaginate": {     
	                "sFirst": "首页",     
	                "sPrevious": "前一页",     
	                "sNext": "后一页",     
	                "sLast": "尾页"    
	          	},
	            "search":"搜索:",
	            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
	            "infoEmpty":      "没有找到匹配的信息",
	         },
	         "ajax": {
	        	 "type": "POST",
	        	 "url":"/kajhsgweasdqtwehghasfdnsak6868/findUserChatRecord.do",
	        	 "dataSrc": function(json) {
	        		 var newData = json.data
	        		 for (var i = 0; i < newData.length; i++) {
	        			 var item = newData[i]
	        			 if (item.type !== null) {
	        				 item.desc = item.type
	        			 } else {
	        				 item.desc = item.desc
	        			 }
	        		 }
	        		 return newData;
	        	 }
	         },
	         "columns": [
						 {"data": "id", "className": "hidden-td id-edit-td"},
	                     {"data": "userid", "className": "userid-edit-td"},
	                     {"data": "desc", "className": "desc-edit-td"},
	                     {"data": "creattime", "className": "creattime-edit-td"},
	                     {"data": null, "defaultContent": "<button class='btn btn-danger btn-c-delBankInfo btn-sm'>删除</button>"},
	                 ]        
	   		 })		
			
	</script>
</body>
</html>